class AppsController < ApplicationController
  def index
    @apps_hash = App.includes(:group).group_by(&:group)
    @apps = App.all
    render 'index'
  end

  def pie
    @app = App.find_by(id: params[:id].to_i)
    render layout: false
  end

  def timeline
    @versions = App.find_by(id: params[:id].to_i).versions
    render layout: false
  end

  def line
    @crash_rate = []
    @versions = App.find_by(id: params[:id].to_i).versions.sort_by(&:id)
    @versions.each do |version|
      @crash_rate<<(((version.fails.to_f/(version.fails + version.success)).round(2))*100).to_i rescue '-' 
    end
    @versions = App.find_by(id: params[:id].to_i).versions.sort_by(&:id)
    render layout: false
  end

end
